﻿/**
 * XES Framework
 * xex.index.js
 * 
 * version 1.0
 * @upload 2010-12-15
 * @author Jay
 */
	$(function(){
	    $(".index_example ul").RollTitle({line:1,speed:200,timespan:1500});
		//$('.xes_menu').css({left:0});	
		if ($('.index_student_list .student_item').length > 0) {
			studentShow($('.index_student_list .student_item')[0]);
		}
		$('.index_student_list .student_item').hover(
			function(){studentCount(this)},
			function(){studentCountClear()}
		);
		$('.xes_menu li').hover(function(){
			$(this).addClass('on').siblings('li').removeClass('on');
		});
		$('.index_results_tab li').mouseover(function(){
			var _i=$('.index_results_tab li').index(this);
			var _m=$('.index_results .index_results_item');
			$(this).addClass('on').siblings('li').removeClass('on');
			_m.eq(_i).show().siblings('.index_results_item').hide();
		});
		//广告条轮播显示
		
		//setInterval( "slideSwitch()", 6000 ); 	//广告条轮播显示
		if ($('#StuStudyTime').length > 0) {
			studyRefreshTime(); 				//网校学员累计学习时间
			//studyTimeShow();					//网校学院累计学习时间读秒
		}
		
		$('body').unbind('mousemove');

		indexFocusTab();
		$('#focusVideo').click(function(){
			videoShow({
				auto:true,
				id:'18947',
				FlashID:'focusVideo',
				type:''
				//,picUrl:'http://file.xueersi.com/web/12942362409568.jpg'
			});
		});
		$('.teacher_pic img').bind('click',function(){
			var _id=this.id.split('teacher_')[1];
			videoShow({
				auto:true,
				id:_id,
				width:'464',
				height:'257',
				picUrl:'',
				hitID:'',
				type:'teacher',
				FlashID:this.id
			});
		});
		/*setIndexTwoBanner();
		setIndexOneBanner();*/
		//setIndexBannerMap();
		tabs('.tab_tit_0120','on','.tab_con_0120');


		//激活代金卡
		activeDJK();
		callUserInfo();
		/*
		//判断用户登录
		
//		$('#indexUserInfo').submit(function(){
//			indexUserLogin();
//		});
		//用户登录框效果
		userloginInputClick();
		*/
		// 首页新版0713
		indexNew0713();

		//20110906
		//dialogRB('http://www.xueersi.com/img/pic/tips20110906.jpg','javascript:void(0);');
	});
	$(window).resize(function(){
		$('.xes_menu').css({left:0});	
	});
/*
	$(window).scroll(function(){
		setIndexTwoBanner();
		setIndexOneBanner();
	});
*/
/*
	function userloginInputClick() {
		var _user=$('#index_username');
		var _pass=$('#index_password');
		var _pass0=$('#index_password_0');
		var _val=_user.val();
		_user.blur(function(){
			if(this.value==''){
				this.value='会员名/邮箱/手机号';
			}
		}).focus(function(){
			if(this.value=='会员名/邮箱/手机号'){
				this.value='';
			}
		});
		_pass0.focus(function(){   
			_pass.show().focus();   
			_pass0.hide();   
		});   
		_pass.blur(function(){   
			if(_pass.val()=='') {   
				_pass0.show();   
				_pass.hide();   
			}   
		});

	}
*/
	/*
	 * 首页学员展示
	 * @param {Object} d
	 */
	function studentShow(d){
		var _item=$(d),
			_main=$('.index_student_main'),
			_list=$('.index_student_list .student_item'),
			_wrap=$('.index_student_wrap'),
			_base=_item.find('.index_student_item'),
			_link=_item.find('a').attr('href');
			
		//高亮
		_item.addClass('on').siblings('li').removeClass('on');
		//显示边框
		if(_wrap.length==0){
			$('body').append('<div class="index_student_wrap"></div>');
		}
		//定位
		$('.index_student_wrap').css({
			left:$(d).offset().left-5,
			top:$(d).offset().top-5
		}).show();
		//设置内容
		var _url=_base.find('.student_pic').attr('name'),
			_tit=_base.find('.student_name').text(),
			_pic='<a href="'+_link+'" onmousedown="hits(\'two09\')" target="_blank"><img src="'+_url+'" alt="'+_tit+'" /></a>';
		_main.empty().append(_base.html());
		_main.find('.student_pic').replaceWith(_pic);
		
	}
	
	/* 
	 * 学员延时展示
	 */
	var timeCount=0,timeMax=2,timeInterval,studentIndex=0;
	function studentCount(d){
		var _index=$('.student_item').index(d),	_item=d;
		timeInterval=setInterval(function(){
			if(timeCount<timeMax){
				timeCount++;
			}else{
				studentIndex=_index;
				studentShow(_item);
				studentCountClear();
			}
		},100);
	}
	function studentCountClear(){
		clearInterval(timeInterval);
		timeCount=0;
	}
	
/*
 * 网校学员累计学习时间
 */
//var studyTimer=0,studyInterval,studyRefresh;
function studyRefreshTime() {
	var _obj = $('#StuStudyTime'),
		_day = 8700;
	_obj.html('网校学员累计学习时间： <em>'+_day+'</em> 天');
	
};

/*
 * 广告热区
 * 一个广告条上出现2个以上链接时调用


 function setIndexBannerMap(){
	//迎春杯、中考复习视频会议
	var _map = '<map name="Map" id="Map">'
				 +'<area shape="rect" coords="506,27,648,64" href="http://www.xueersi.com/search?keyword=%E6%98%A5%E5%AD%A3&grade=8&price=0" target="_blank" onmousedown="hits(\'ad201\')" />'
				 +'<area shape="rect" coords="662,30,804,65" href="http://www.xueersi.com/search?keyword=%E6%98%A5%E5%AD%A3&grade=9&price=0" target="_blank" onmousedown="hits(\'ad202\')" />'
				 +'<area shape="rect" coords="817,30,960,65" href="http://zt.xueersi.com/chusan/" target="_blank" onmousedown="hits(\'ad203\')" />'
				 +'</map>';
	var _img=$('.banner').find('img[lazyload="http://file.xueersi.com/web/12994681051131.jpg"]');
	if(_img.length==0){
		_img=$('.banner').find('img[src="http://file.xueersi.com/web/12994681051131.jpg"]');
	}
	_img.attr({	usemap:'#Map'	}).parent('a').removeAttr('target').removeAttr('href');
	$('body').append(_map);

}

 function setIndexOneBanner(){
	//迎春杯、中考复习视频会议
	var _map = '<map name="Map" id="Map">'
				 +'   <area shape="rect" coords="109,16,507,45" href="http://www.xueersi.com/article/detail/1158" target="_blank" />'
				 +'   <area shape="rect" coords="578,13,944,47" href="http://www.xueersi.com/article/detail/1157" target="_blank" />'
				 +'</map>';
	var _img=$('.banner').find('img[lazyload="http://file.xueersi.com/web/12952570559444.jpg"]');
	if(_img.length==0){
		_img=$('.banner').find('img[src="http://file.xueersi.com/web/12952570559444.jpg"]');
	}
	_img.attr({	usemap:'#Map'	}).parent('a').removeAttr('target').removeAttr('href');
	$('body').append(_map);

}

function setIndexTwoBanner(){
	// 五大杯赛
	var _map = '<map name="Maprr" id="Maprr">'
				 +'   <area shape="rect" coords="456,31,542,64" href="http://zt.xueersi.com/zt_xwb" target="_blank" />'
				 +'   <area shape="rect" coords="557,30,645,63" href="http://zt.xueersi.com/zt_zoumei" target="_blank" />'
				 +'   <area shape="rect" coords="659,29,750,65" href="http://zt.xueersi.com/zt_huabei" target="_blank" />'
				 +'   <area shape="rect" coords="764,31,853,64" href="http://zt.xueersi.com/zt_ycbfs" target="_blank" />'
				 +'	  <area shape="rect" coords="866,30,956,65" href="http://zt.xueersi.com/zt_zhbei" target="_blank" />'
				 +'</map>';
	var _img=$('.banner').find('img[lazyload="http://file.xueersi.com/web/12942375453312.jpg"]');
	if(_img.length==0){
		_img=$('.banner').find('img[src="http://file.xueersi.com/web/12942375453312.jpg"]');
	}
	_img.attr({	usemap:'#Maprr'	}).parent('a').removeAttr('target').removeAttr('href');
	$('body').append(_map);

}
 */


	// 弹出视频播放详细页面
	function showDetailDialog(div, width, height, url, title, t_id) {
		var _ui=$('script[src="/js/jquery-ui-1.8.2.custom.js"]');
		$.getScript('/js/jquery-ui-1.8.2.custom.js',function(){
            $('#' + div).dialog({
                draggable: true,
                resizable: false,
                closeOnEscape: true,
                bgiframe: true,
                height: height,
                width: width,
                maxHeight: 1000,
                minHeight: 100,
                maxWidth: 1200,
                minWidth: 100,
                title: title,
                modal: true,
                close: function() {
                    $(this).dialog('destroy');
                }
            }).html('Loading...').load(url, '', function() {
				videoShow({
					auto:true,
					id:t_id,
					width:'680',
					height:'410',
					picUrl:'',
					hitID:'',
					type:'teacher',
					FlashID:'videoPlayer'
				});
			});
		});

	};

/* 2011-01-20 */
/* indexUserLogin */
//监听回车
// $(function(){
	// $("#index_password").keyup(function(event){
		 // if (event.keyCode == 13) {
             // indexUserLogin();
        // }
	// });
// })
// function indexUserLogin () {
	// var username=$.trim($("#index_username").val());
	// var password=$.trim($("#index_password").val());
	// var params="data[Cas][username]="+username+"&data[Cas][password]="+password;
	// var _a=window.location.host,
		// //_url=_a=='www.wss2.0.com'?'logintest.xueersi.org':'login.xueersi.org';
		// _url=_a=='www.xueersi.com'?'login.xueersi.org':'logintest.xueersi.org';
// 
    // if (username == '邮箱/手机/用户名') {
    	// alert('请填写用户名！');
    	// return false;
    // }
// 
    // $.ajax({
        // type: "post",
        // url: 'http://' + localhostName + '/users/userLogin',
        // dataType: "json",
        // timeout: 7000,
        // data: params,
        // success: function(msg) {
            // if(msg.sign == true){
				// //$("#casiframe").html('<iframe src="http://reg010.eduu.com/cas/actlogin/?tk='+msg.casid+'" width="0" height="0" style = "display:none"></iframe>');
				// $("#casiframe").html('<iframe src="http://'+_url+'/cas/actlogin/?tk='+msg.casid+'" width="0" height="0" style = "display:none"></iframe>');
				// $("#userInfo1").hide();
				// $("#userInfoLoading").show();
				// callUserInfo();
            // }else{
                // alert(msg.loginErrorMsg);
            // }
        // },
        // error: function() {
            // alert('数据读取错误..');
        // }
    // });
// }

/* 返回用户信息  */

function callUserInfo(){
	var url='http://' + localhostName + '/users/getSpUrl?jsoncallback=?';
	$.getJSON(url,function(d){
		var _order=d.ordernum!=null?d.ordernum:0,
			_user=d.name!=null?d.name:'';
		if(d.name!=null){
			$('#ordernum').text(_order);
			$('#userInfo2 .info1').text(_user+'同学，欢迎您来到学而思网校！');
			var htmlTitle = $($('.welcome_info')[1]);
			htmlTitle.html(''+_user+',欢迎您!&nbsp;&nbsp;&nbsp;<a href="http://i.xueersi.com/"  xes_id="banner14">个人中心</a>&nbsp;&nbsp;&nbsp;<a href="http://'+_hostName+'/users/logout/" xes_id="banner15">退出</a>');
			$("#userInfo2").show();
			$("#userInfoLoading").hide();
	}else{
			$('#userInfo1').show();
			$('#userInfo2,#userInfoLoading').hide();
		}
	});	
}

// 焦点图切换
function indexFocusTab(){
	var _box=$('.focus_video_list li');
	var _num='<ol class="focus_video_num">';
	if ($('.focus_video_num').length == 0) {
		for (var i = 0, len = _box.length; i < len; i++) {
			_num += '<li class=""><a href="javascript:void(0);">' + (i + 1) + '</a></li>';
		}
		_num += '</ol>';
		$('.focus_video_list').after(_num);
	}
	var _tab=$('.focus_video_num li');
	_box.eq(0).show().css('z-index','101').siblings('li').css('z-index','100');
	_tab.eq(0).addClass('on').siblings('li').removeClass('on');
	_tab.live('mouseover',function(){
		var _i=_tab.index(this);
		$(this).addClass('on').siblings('li').removeClass('on');
		_box.eq(_i).css('z-index','101').siblings('li').css('z-index','100');
	});
}
// 自动播放
$(function(){
	indexFocusSwitch();
});
var IndexFocusAuto,videoPlaying;
function indexFocusSwitch(){
	var _index = 0,_timer=5000;
	var _num = $('.focus_video_num li');
	var _videoIndex=$('.focus_video_list li').index($('#focusVideo').parent('li')[0]);
	IndexFocusAuto = setInterval(function(){
		_showPic(_index);
		_index++;
		if(_index == _num.length ){_index=0}
	},_timer);	
	function _showPic(i){
		$('.focus_video_list li').eq(i).show().css('z-index','101').siblings('li').css('z-index','100');
		$('.focus_video_num li').eq(i).addClass('on').siblings().removeClass('on');
	}
	$('.focus_video_0120').hover(function(){
		if(IndexFocusAuto){
			clearInterval(IndexFocusAuto);
		}
	},function(){
		if (!videoPlaying) {
			IndexFocusAuto = setInterval(function(){
				_showPic(_index);
				_index++;
				if (_index == _num.length) {
					_index = 0
				}
			}, _timer);
		}else{
			clearInterval(IndexFocusAuto);
			_showPic(_videoIndex);			
		}
	});
	$('#focusVideo').live('mousedown',function(){
		clearInterval(IndexFocusAuto);
		videoPlaying=true;
	});
}

/*
 * 激活代金卡
 */
function activeDJK(){
	var _btn=$('.l_s_ad2_0120').find('img[src="http://file.xueersi.com/web/13001798533217.jpg"]');
	if(_btn.length>0&&checkLogin()){
//		_btn.parent().attr('href','http://i.xueersi.com/my_yhcards/active');
		_btn.parent().attr('href','http://i.xueersi.com/MyCards/giftCard/');
	}

}
//-------------------------------
/*
 * 首页顶部擎天柱广告：第三代个人中心
 * @param {Object} o
 */
 /*
(function(o){
	var _box=o.box||$('#bannerIndexTop'),
		_cname=o.cookieName||'topbanner',
		_isPosition=o.isPosition||false,
		_outTime=o.times||10000,
		_isRepeat=o.isRepeat||false;

	if(_isRepeat){	xesCookie.clear(_cname);}
	if(!xesCookie.get(_cname)){
		if(_isPosition){
			var _top=$('.header_0118');
			_box.css({
				position:'absolute'
				,zIndex:'1000'
				,top:0
				,left:_top.offset().left
			})	
		}
		_box.prependTo('body').animate({
			height:'413px'
		},1000,function(){
			_box.stop();
			_topbannerClose();
		});
	}
	function _topbannerClose(){
		setTimeout(function(){
			_box.animate({
				height:0
				,opacity:'hide'
			},1000,function(){
				xesCookie.set(_cname,'read');
			});
		},_outTime);
	}
})({
	box:$('#bannerIndexTop'),
	cookieName:'topbanner',		//Cookie名称
	isPosition:false,			//是否绝对定位（页面内容是否跟随广告移动）
	times:5000,				//显示停留时间10秒
	isRepeat:false				//是否重复显示
});
*/

/*
 * 首页改版新增效果
 * upload：2011-07-13
 */
function indexNew0713() {
    /**文字滚动**/
    var speed = 30; 
	var tab = $("#textScrollArea")[0];
	var tab1 = $("#textScrollCon1")[0];
	var tab2 = $("#textScrollCon2")[0];
	tab2.innerHTML = tab1.innerHTML;
	function Marquee() {
	if (tab2.offsetWidth - tab.scrollLeft <= 0)
	tab.scrollLeft -= tab1.offsetWidth
	else {
	tab.scrollLeft++;
	}
	}
	var MyMar = setInterval(Marquee, speed);
	tab.onmouseover = function() { clearInterval(MyMar) };
	tab.onmouseout = function() { MyMar = setInterval(Marquee, speed) }; 
	
	/***tab切换**/
	$('.tab_tit_0226 a').mouseover(function(){
		 $(this).addClass('current').siblings().removeClass('current');
		 var _eq = $('.tab_tit_0226 a').index(this);
		 var tabContent = $('.tab_con_0120 ul').eq(_eq);
		 tabContent.show().siblings().hide();
		 if(_eq==0){
		    $(this).css('border-left','0');
		 }else{
		    $(this).css('border-left','1px solid #ccc').siblings().css('border-left','0');
		 }
	});
	
	/***tab切换**/
	$('.nav_0226 li').live('mouseover', function(){
		 $(this).addClass('current').siblings().removeClass('current');
		 var tabIndex = $(this).index();
		 var tabContent = $('.tab-teacher .teacher_show_list').eq(tabIndex);
		 var tabName = $('.tab-name .teacher_Name_show').eq(tabIndex);
		 tabContent.show().siblings().hide();
		 tabName.show().siblings().hide();
	});
	$('.hotKindsConArea').hover(function(){
		$(this).addClass('current');
	},function(){
		$(this).removeClass('current');
	});
}